package com.downloading.bezoyaapp;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

import com.downloading.bezoyaapp.support.utils.Constraints;

import android.app.Activity;
import android.os.Bundle;
import android.provider.SyncStateContract.Constants;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class HttpConnectionPrueba extends Activity {

	Button pedirNumDevices;
	Button pedirNumAlimentos;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_http_connection_prueba);

		pedirNumAlimentos = (Button) findViewById(R.id.prueba_pedirNumAlimentos_button);
		pedirNumDevices = (Button) findViewById(R.id.prueba_pedirNumDevices_button);

		pedirNumAlimentos.setOnClickListener(new PedirNumAlimentos());
		pedirNumDevices.setOnClickListener(new PedirNumDevices());

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_http_connection_prueba, menu);
		return true;
	}

	private class PedirNumAlimentos implements OnClickListener {

		@Override
		public void onClick(View v) {
			HttpURLConnection conection;
			try {
				URL url = new URL(Constraints.SERVER_URL + "/prueba");
				conection = (HttpURLConnection) url.openConnection();

				InputStream in = new BufferedInputStream(
						conection.getInputStream());

				Log.i("HTTPPRUEBA", in.toString());

				conection.disconnect();

			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();

			}
		}
	}

	private class PedirNumDevices implements OnClickListener {

		@Override
		public void onClick(View v) {

		}

	}

}
